<div class="layuimini-main">

    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">角色名</label>
            <div class="layui-input-block">
                <input type="text" name="label" maxlength="30"   lay-verify="required" lay-reqtext="角色名不能为空" placeholder="请输入角色名" value="" class="layui-input">
              
            </div>
        </div>
		
        <div class="layui-form-item">
            <label class="layui-form-label required">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="0" title="正常" checked="">
                <input type="radio" name="status" value="1" title="禁用">
            </div>
        </div>
        
        <div class="layui-form-item">
            <label class="layui-form-label">别名</label>
            <div class="layui-input-block">
                <input type="text" name="alias" id="user_name_verify" maxlength="30" lay-verify="required" placeholder="请输入别名" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <input type="text" name="remark" maxlength="255"  placeholder="请输入描述" value="" class="layui-input">
            </div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="number" name="sort" max="999999" onkeyup="if(value.length>6) value=value.substr(0,6)"  placeholder="请输入数字" value="0" class="layui-input">
				 <tip>数字越大排序越靠前 范围：0 - 999999 </tip>
			</div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
           
			 var url = "/admin/rbac/roleAdd"
            $.post(url,data.field,function(resp){
				//console.log(resp)
				if(resp.code == 0){
					//成功
					layer.msg("添加成功",{end:function(){
						table.reload('roleCurrentTableId')
						 // 关闭弹出层
						layer.close(parentIndex);
					}});
					
				}else{
					layer.msg(resp.msg);
				}
		    },"json");

            return false;
        });
		
		//角色文字过滤
		$("#user_name_verify").keyup(function(){
			var biaoshi_str = $(this).val();
			var replace_str = biaoshi_str.replace(/[^a-zA-Z0-9]/g,'')
			$(this).val(replace_str);
			
		});
		

    });
	
</script>